package com.exam.Interceptor;

import com.exam.Domain.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName loginInterceptor
 * @Description
 * @Author JY
 * @Date 2020/6/1 15:48
 **/
public class loginInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object user = request.getSession().getAttribute("user");

        if (user==null){
            request.setAttribute("message","无权限请先登录");
            request.getRequestDispatcher("/").forward(request, response);
            return false;
        }
        return true;
    }
}
